package com.panda.web.controller.wechatinfo;

import java.util.List;
import java.util.Arrays;
import com.panda.common.core.domain.R;
import com.panda.web.domain.dto.wechatinfo.UserinfoDTO;
import com.panda.web.domain.vo.commons.AddressVO;
import com.panda.web.domain.vo.wechatinfo.UserinfoVO;
import com.panda.web.service.wechatinfo.IWechatUserinfoService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.panda.web.utils.pageutils.PageResult;

import com.panda.common.annotation.Log;
import com.panda.common.core.controller.BaseController;
import com.panda.common.core.domain.AjaxResult;
import com.panda.common.enums.BusinessType;


/**
 * 用户个人信息Controller
 *
 * @author cpanda
 * @date 2025-03-04
 */
@CrossOrigin
@RestController
@RequestMapping("/web/userinfo")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class WechatUserinfoController extends BaseController {
    private final IWechatUserinfoService userinfoService;

    /**
     * 查询用户个人信息列表
     */
    @GetMapping("/list")
    public PageResult<UserinfoVO> List(UserinfoDTO dto,
                                       @RequestParam("pageNum") Integer pageNum,
                                       @RequestParam("pageSize") Integer pageSize) {
        //返回分页信息
        PageResult<UserinfoVO> voList = userinfoService.PageList(dto,pageNum,pageSize);
        return voList;
    }


    /**
     * 查询用户个人信息列表 无分页
     */
    @GetMapping("/choiceList")
    public R choiceList(UserinfoDTO dto) {
        List<UserinfoVO> voList = userinfoService.choiceList(dto);
        return R.ok(voList,"ok");
    }

    /**
     * 获取用户个人信息详细信息
     */
    @GetMapping(value = "/{openid}")
    public AjaxResult getInfo(@PathVariable("openid") String openid) {
        return AjaxResult.success(userinfoService.selectById(openid));
    }

    /**
     * 新增用户个人信息
     */
    @Log(title = "用户个人信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserinfoDTO dto) {
        return toAjax(userinfoService.insert(dto));
    }

    /**
     * 修改用户个人信息
     */
    @Log(title = "用户个人信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserinfoDTO dto) {
        return toAjax(userinfoService.updateUserinfoById(dto));
    }

    /**
     * 删除用户个人信息
     */
    @Log(title = "用户个人信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{openids}")
    public AjaxResult remove(@PathVariable Long[] openids) {
        return toAjax(userinfoService.removeByUserinfoIds(Arrays.asList(openids)));
    }

    /**
     * 人岗匹配 地址搜索
     */
    @GetMapping("/address")
    public R address(String openid){
     List<AddressVO> addressList=userinfoService.address(openid);
     return R.ok(addressList,200,"ok");
    }
}
